package com.cr.api.controller;

import com.cr.api.vo.AmountFlowVo;
import com.cr.api.vo.ServiceVo;
import com.cr.business.domain.CrAmountFlow;
import com.cr.business.domain.CrService;
import com.cr.business.domain.CrServiceApplicationRecord;
import com.cr.business.domain.CrUser;
import com.cr.business.service.ICrAmountFlowService;
import com.cr.business.service.ICrServiceApplicationRecordService;
import com.cr.business.service.ICrServiceService;
import com.cr.business.service.ICrUserService;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.utils.ConvertUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 金点子服务Controller
 * 
 * @author G
 * @date 2021-09-14
 */
@Api(tags = "流水", value = "流水")
@RestController
@CrossOrigin
@RequestMapping("/api/flow")
public class ApiFlowController extends BaseController
{
    @Autowired
    private ICrUserService userService;
    @Autowired
    private ICrAmountFlowService amountFlowService;
    /**
     * 我的财富
     */
    @ApiOperation("我的财富")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long"),
//    })
    @PostMapping("/getAmount")
    @ResponseBody
    public AjaxResult getAmount(@RequestBody CrUser user)
    {
        Long userId = user.getUserId();
        //余额
        user = userService.selectCrUserByUserId(userId);
        //流水
        startPage();
        CrAmountFlow amountFlow = new CrAmountFlow();
        amountFlow.setUserId(userId);
        List<CrAmountFlow> amountFlowList = amountFlowService.selectCrAmountFlowList(amountFlow);
        List<AmountFlowVo> voList = new ArrayList<>();
        for (CrAmountFlow entity : amountFlowList){
            AmountFlowVo vo = new AmountFlowVo();
            BeanUtils.copyProperties(entity, vo);
            vo.setChannel("银联支付");
            //0债权交易，1债权线索，2金点子服务
            if(vo.getType() == 0){
                vo.setTypeName("债权交易");
            } else if(vo.getType() == 1){
                vo.setTypeName("债权线索");
            }else if(vo.getType() == 2){
                vo.setTypeName("金点子服务");
            }
            //@ApiModelProperty("方式 0收入，1支出")
            if(vo.getMode() == 0){
                vo.setModeName("收入");
            } else {
                vo.setModeName("支出");
            }
            voList.add(vo);
        }

        Map<String, Object> map = new HashMap<>();
        map.put("amount", user.getBalance());
        map.put("flow", new PageInfo<>(voList));
        return AjaxResult.success(map);
    }
}
